﻿@model BskLeague.Models.Player


@{
    ViewBag.Title = "Zawodnik - " + @Model.PlayerName + " " + @Model.PlayerSurname;
}

@if (User.IsInRole("Player") && Model.UserName == User.Identity.Name)
{
        @Html.Partial("~/Views/MyPlayer/_Submenu.cshtml")
}

<h2>Szczegóły zawodnika</h2>
<table cellspacing="0" cellpadding="0" width="100%">
    <tr>
        <th colspan="3">@Model.PlayerName @Model.PlayerSurname</th>
    </tr>
    <tr>
        <td rowspan="9" width="150px" height="150px">
        @{
            if (@Model.Photo == null)
            {
                @MvcHtmlString.Create("<img src=\"/Content/images/user_photo/default.jpg\" alt=\"Brak Zdjęcia\"/>");
            }
            else
            {
                <text><img src="@Model.Photo" alt="@Model.PlayerName @Model.PlayerSurname"/></text>
            }
        }
        </td>
        @if (Model.Team != null)
        {
            <tr>
                <td>Aktualna drużyna</td>
                <td>@Html.ActionLink(@Model.Team.TeamName, "Details/" + @Model.Team.TeamId, "Team")</td>
            </tr>
        }
        else if (@ViewBag.LastTeamID != null)
        {
            <tr>
                <td>Ostatnia drużyna</td>
                <td>@Html.ActionLink((string)@ViewBag.LastTeamName, "Details/" + (int)@ViewBag.LastTeamID, "Team") (@ViewBag.LastSeasonPlayedIn)</td>
            </tr>
        }
        else
        {
            <tr>
                <td>Drużyna</td>
                <td>Brak</td>
            </tr>
        }

        @if (Model.Date != null)
        {<tr><td>Data Urodzenia</td>                 <td>@Model.Date.ToLongDateString() </td></tr>}
        @if (Model.Licence != null)
        {<tr><td><text>Numer licencji</text></td>   <td>@Model.LicenceId</td></tr>}
        @if (Model.PlayerNumber != null)
        {<tr><td>Numer zawodnika</td>               <td>@Model.PlayerNumber</td></tr>}
        @if (Model.Height != null)
        {<tr><td>Wzrost</td>                        <td>@Model.Height cm</td></tr>}
        @if (Model.Weight != null)
        {<tr><td>Waga</td>                          <td>@Model.Weight kg</td></tr>}
        @if (Model.Email != null)
        {<tr><td>E-Mail</td>                        <td><a href="mailto:@Model.Email">@Model.Email</a></td></tr>}
        @if (Model.About != null)
        {<tr><td>O sobie</td>                       <td>@Model.About</td></tr>}

    </tr>
</table><br />

<center><table cellspacing="0" cellpadding="0" border="1" width="100%">
@if (@ViewBag.TotalItemsCount > 0)
{
        <tr>
            <td colspan="6" style="text-align:center;"><b>Statystyki wybranych meczów</b></td>
        </tr>
        <tr align="center" >
            <th style="text-align:center;">Data</th>
            <th style="text-align:center;">Mecz</th>
            <th style="text-align:center;">Minut na boisku</th>
            <th style="text-align:center;">Zdobyte Punkty (Połowa/Łącznie)</th>
            <th style="text-align:center;">Faule</th>
        </tr>


    try
    {
        @ViewBag.SeasonTemp
        for (int i = 0; i < @ViewBag.Minutes.Count; i++)
        {
            if (@ViewBag.Season[i] != @ViewBag.Temp)
            {<tr align="center">
                    <td colspan="5"><b>Sezon @ViewBag.Season[i]</b></td>
                    @{ViewBag.Temp = @ViewBag.Season[i];}
            </tr>
            }
            <tr align="center">
                <td>@ViewBag.Date[i]</td>
                <td>@Html.ActionLink((string)@ViewBag.Team1Name[i], "Details/" + (string)@ViewBag.Team1ID[i].ToString(), "Team")
                    vs. @Html.ActionLink((string)@ViewBag.Team2Name[i], "Details/" + (string)@ViewBag.Team2ID[i].ToString(), "Team")</td>
                <td>@ViewBag.Minutes[i]</td>
                <td><b>@ViewBag.PointsHalf[i]/@ViewBag.PointsTotal[i]</b></td>
                <td><b>@ViewBag.Fauls[i]</b></td>
            </tr>
        }
    }
    catch (Exception exc)
        {@exc}
    if (@ViewBag.TotalItemsCount > @ViewBag.Take)
    {<tr>
        <th colspan="5">
            <center>
                <
                @{
        int temp = @ViewBag.TotalItemsCount / @ViewBag.Take;
        temp = ((@ViewBag.TotalItemsCount % @ViewBag.Take) != 0) ? ++temp : temp;
                }
                @for (int i = 0; i < temp; i++)
                {
                    if (@ViewBag.From / @ViewBag.Take == i)
                    {<text>@(i + 1) </text>}
                    else
                    {
                        @Html.ActionLink((i + 1).ToString(),
                                        "Details/",
                                        "Players",
                                        new
                                        {
                                            id = @ViewBag.Id,
                                            from = (i * @ViewBag.Take),
                                            take = @ViewBag.Take
                                        },
                                        null)
                        <text> </text>
                    }
                }
                >
            </center>
        </th>
    </tr>
    }
    <tr>
        <td colspan="5" align="center">
        @using (Html.BeginForm("Details", "Players", FormMethod.Get))
        {
            <text>Wyświetl </text>@Html.DropDownList("take", new SelectList(new[]{new KeyValuePair<string, int>("5",5),
                                                    new KeyValuePair<string, int>("7", 7),
                                                    new KeyValuePair<string, int>("10", 10)},
                                                    "Value", "Key"));
            <text>pozycji na stronie.</text>
                                                               
            <input type="submit" value="Zatwierdź" />
        }
        </td>
    </tr>
}

else
{
    <tr><th><center>Gracz nie posiada zapisanych meczów.</center></th></tr>
}
</table></center>

    @if (@ViewBag.TotalItemsCount > 1)
    {
        <br /><table cellspacing="0" cellpadding="0" border="1" width="100%">
            <tr><td colspan="5"><center><b>Rekordy zawodnika</b></center></td></tr>
            <tr align="center">
                <td style="text-align:center;"></td>
                <th style="text-align:center;">Rekord</th>
                <th style="text-align:center;">W meczu</th>
                <th style="text-align:center;">Data</th>
                <th style="text-align:center;">Sezon</th>
            </tr>
            <tr align="center">
                <th style="text-align:center;">Punkty</th>
                <td>@ViewBag.BestScorePoints</td>
                <td>@Html.ActionLink((string)@ViewBag.BestScoreTeam1, "Details/" + (string)@ViewBag.BestScoreTeamId1.ToString(), "Team")
                     vs. @Html.ActionLink((string)@ViewBag.BestScoreTeam2, "Details/" + (string)@ViewBag.BestScoreTeamId2.ToString(), "Team")
                </td>
                <td>@ViewBag.BestScoreDate</td>
                <td>@ViewBag.BestScoreSeason</td>
            </tr>
            <tr align="center">
                <th style="text-align:center;">Faule</th>
                <td>@ViewBag.MostFauls</td>
                <td>@Html.ActionLink((string)@ViewBag.MostFaulsTeam1, "Details/" + (string)@ViewBag.MostFaulsTeamId1.ToString(), "Team")
                     vs. @Html.ActionLink((string)@ViewBag.MostFaulsTeam2, "Details/" + (string)@ViewBag.MostFaulsTeamId2.ToString(), "Team")
                </td>
                <td>@ViewBag.MostFaulsDate</td>
                <td>@ViewBag.MostFaulsSeason</td>
            </tr>
            <tr align="center">
                <th style="text-align:center;">Minuty na boisku</th>
                <td>@ViewBag.MostMinutes</td>
                <td>@Html.ActionLink((string)@ViewBag.MostMinutesTeam1, "Details/" + (string)@ViewBag.MostMinutesTeamId1.ToString(), "Team")
                     vs. @Html.ActionLink((string)@ViewBag.MostMinutesTeam2, "Details/" + (string)@ViewBag.MostMinutesTeamId2.ToString(), "Team")
                </td>
                <td>@ViewBag.MostMinutesDate</td>
                <td>@ViewBag.MostMinutesSeason</td>
            </tr>
        </table>
    }


    <br /><table cellspacing="0" cellpadding="0" border="1" width="100%">
        <tr><td colspan="2"><center><b>Historia drużyn</b></center></td></tr>
        <tr align="center">
            <th style="text-align:center;">Drużyna</th>
            <th style="text-align:center;">Sezon</th>
        </tr>
        @{  
            for(int i=0; i<@ViewBag.teamHistoryNames.Count; i++)
            {
            <tr align="center">
                <td>@Html.ActionLink((string)@ViewBag.teamHistoryNames[i], "Details/" + (string)@ViewBag.teamHistoryIds[i].ToString(), "Team")</td>
                <td>@ViewBag.teamHistorySeasons[i]</td>
            </tr>
            }
        }
        <tr align="center">
        </tr>
    </table>